const urlParams = new URLSearchParams(new URL(window.location.href).search);
let resourceId = urlParams.get('id');
let declareStatus = urlParams.get('declareStatus');
let isCloseImg =  !(Number(declareStatus) == 0 || Number(declareStatus) == 1)
let declareByCreaterId
let datas = {}
let flag1 = 1
let flag2 = 1
let flag3 = 1
let flag = false
let myOrgName;
let practiceClick1 = !(Number(declareStatus) == 0 || Number(declareStatus) == 1),
    restrictPracticeClick1 = !(Number(declareStatus) == 0 || Number(declareStatus) == 1),
    restrictPracticeClick2 = !(Number(declareStatus) == 0 || Number(declareStatus) == 1)
let certificateNum



//数据回显
const echo = async () => {
  await $.ajax({
        type: 'GET',
        url: '/jzweb/declare/getDeclareByCreaterId',
        contentType: 'application/json', // 将content-type设置为application/json
        data: {
            declareReadyId: resourceId,
        },
        beforeSend: function (request) {
            request.setRequestHeader("Authorization", window.localStorage.getItem("token"))
        },
        success: async (data)=> {
            if (data.code === '0') {
                // 设置数据
                if(data.data&&data.data.length>0){
                   await setDatas(data.data[0])
                }
            }
        },
        error: function (xhr, textStatus, error) {
            layer.msg('请求失败');
        }
    });
  console.log('===>>>')
}
//设置数据
const setDatas = async (data) => {
    declareByCreaterId = data.id
    if (null != declareByCreaterId && '' != declareByCreaterId.trim()) {
        $('#btnsubmit').text('提交修改')
    }
    if (null != data.remark && '' != data.remark.trim()) {
        $('#refuse').html(`
         <h3>拒绝原因</h3>  
         <div style="color: red; width: 100%;  overflow: auto;">${data.remark}</div>
         `)
        $('#refuse').show()

    }
    myOrgName=data.orgName
    $("#certificateList_text").val(data.orgName)
    $("#certificateList").val(data.orgId)
    $("#contacts").val(data.contacts)
    $("#position").val(data.place)
    $("#position1").val(data.position)//职位
    $("#phone").val(data.phone)
    await AreaSetInit(data.province, data.city);
    let num1 = -1, num2 = -1, num3 = -1,num4 = -1;
    if (null != data.declareTypeDOS && data.declareTypeDOS.length > 0) {
        for (let res of data.declareTypeDOS) {
            switch (Number(res.type)) {
                //1.实习单位 2.优秀培训教师3.优秀考务工作者4.特殊贡献奖5.优秀案例
                //可以多个
                case 1:
                    num1++;
                    if (num1 == 0) {
                        $("#name1").val(res.name);
                        $("#section").val(res.section);
                        $("#phone1").val(res.phone);
                        $("#certType1").val(res.certType)
                        form.render("select");
                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料,2视频
                                    case 0:
                                        $(`#employmentUnits`).text(item.name)
                                        $(`#employmentUnits`).attr('data-id', item.file)
                                        $(`#employmentUnits`).attr('title', item.name)
                                        if (isCloseImg) $(`#employmentUnits`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#jobFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#storysText`).text(item.name)
                                        $(`#storysText`).attr('data-id', item.file)
                                        $(`#storysText`).attr('title', item.name)
                                        if (isCloseImg) $(`#storysText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#introFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 2:
                                        $(`#videoText`).text(item.name)
                                        $(`#videoText`).attr('data-id', item.file)
                                        $(`#videoText`).attr('title', item.name)
                                        if (isCloseImg) $(`#videoText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#videoFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }
                    } else {
                        //新增
                        await practiceClick('employmentUnitDoms', 'outstandingInternshipdel', 1)

                        //设置数据
                        let mydiv = $('.employmentUnitDoms .employmentUnitDoms-box')
                        $(mydiv[mydiv.length - 1]).find("input[name='name']").val(res.name)
                        $(mydiv[mydiv.length - 1]).find("input[name='section']").val(res.section)
                        $(mydiv[mydiv.length - 1]).find("input[name='phone']").val(res.phone)
                        $(mydiv[mydiv.length - 1]).find("select[name='certType']").val(res.certType)
                        form.render("select");
                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料,2视频
                                    case 0:
                                        $(`#employmentUnits${num1}`).text(item.name)
                                        $(`#employmentUnits${num1}`).attr('data-id', item.file)
                                        $(`#employmentUnits${num1}`).attr('title', item.name)
                                        if (isCloseImg) $(`#employmentUnits${num1}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#jobFile${num1}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#storysText${num1}`).text(item.name)
                                        $(`#storysText${num1}`).attr('data-id', item.file)
                                        $(`#storysText${num1}`).attr('title', item.name)
                                        if (isCloseImg) $(`#storysText${num1}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#introFile${num1}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 2:
                                        $(`#textUpload${num1}`).text(item.name)
                                        $(`#textUpload${num1}`).attr('data-id', item.file)
                                        $(`#textUpload${num1}`).attr('title', item.name)
                                        if (isCloseImg) $(`#textUpload${num1}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#videoFile${num1}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }
                    }
                    break;
                case 2:
                    num2++;
                    if (num2 == 0) {
                        $("#name2").val(res.name);
                        $("#card").val(res.card);
                        $("#phone2").val(res.phone);
                        $("#cert_typez").val(res.certType);
                        form.render("select");
                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料
                                    case 0:
                                        $(`#teachertext`).text(item.name)
                                        $(`#teachertext`).attr('data-id', item.file)
                                        $(`#teachertext`).attr('title', item.name)
                                        if (isCloseImg) $(`#teachertext`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#TeacherFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#outstandingText`).text(item.name)
                                        $(`#outstandingText`).attr('data-id', item.file)
                                        $(`#outstandingText`).attr('title', item.name)
                                        if (isCloseImg) $(`#outstandingText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#outstandingFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }
                    } else {
                        await restrictPracticeClick('excellenTeacherDoms', 'excellentTeacherdel', 2)

                        //设置数据
                        let mydiv = $('.excellenTeacherDoms .excellenTeacherDoms-box')
                        $(mydiv[mydiv.length - 1]).find("input[name='name']").val(res.name)
                        $(mydiv[mydiv.length - 1]).find("input[name='card']").val(res.card)
                        $(mydiv[mydiv.length - 1]).find("input[name='phone']").val(res.phone)
                        $(mydiv[mydiv.length - 1]).find("select[name='certType']").val(res.certType)
                        form.render('select')
                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料
                                    case 0:
                                        $(`#teachertext${num2}`).text(item.name)
                                        $(`#teachertext${num2}`).attr('data-id', item.file)
                                        $(`#teachertext${num2}`).attr('title', item.name)
                                        if (isCloseImg) $(`#teachertext${num2}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#TeacherFile${num2}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#outstandingText${num2}`).text(item.name)
                                        $(`#outstandingText${num2}`).attr('data-id', item.file)
                                        $(`#outstandingText${num2}`).attr('title', item.name)
                                        if (isCloseImg) $(`#outstandingText${num2}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#outstandingFile${num2}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }

                    }
                    break;
                case 3:
                    num3++;
                    if (num3 == 0) {
                        $("#name3").val(res.name);
                        $("#IdNumber3").val(res.card);
                        $("#phone3").val(res.phone);
                        $("#cert_typey").val(res.certType);
                        form.render("select");
                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料
                                    case 0:
                                        $(`#Teacherstext`).text(item.name)
                                        $(`#Teacherstext`).attr('data-id', item.file)
                                        $(`#Teacherstext`).attr('title', item.name)
                                        if (isCloseImg) $(`#Teacherstext`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#TeachersFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#trainText`).text(item.name)
                                        $(`#trainText`).attr('data-id', item.file)
                                        $(`#trainText`).attr('title', item.name)
                                        if (isCloseImg) $(`#trainText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#trainFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }
                    } else {
                        await restrictPracticeClick('Excellentexaminationworker', 'Excellentexaminationworker-box', 3)

                        //设置数据
                        let mydiv = $('.Excellentexaminationworker .Excellentexaminationworker-box')
                        $(mydiv[mydiv.length - 1]).find("input[name='name']").val(res.name)
                        $(mydiv[mydiv.length - 1]).find("input[name='card']").val(res.card)
                        $(mydiv[mydiv.length - 1]).find("input[name='phone']").val(res.phone)
                        $(mydiv[mydiv.length - 1]).find("select[name='certType']").val(res.certType)
                        form.render('select')
                        $('#excellentWorkerdel').css("display", "unset");
                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料
                                    case 0:
                                        $(`#Teacherstext${num3}`).text(item.name)
                                        $(`#Teacherstext${num3}`).attr('data-id', item.file)
                                        $(`#Teacherstext${num3}`).attr('title', item.name)
                                        if (isCloseImg) $(`#Teacherstext${num3}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#TeachersFile${num3}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#trainText${num3}`).text(item.name)
                                        $(`#trainText${num3}`).attr('data-id', item.file)
                                        $(`#trainText${num3}`).attr('title', item.name)
                                        if (isCloseImg) $(`#trainText${num3}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#trainFile${num3}`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }
                    }

                    break;
                case 4:
                    //两个
                    num4++;
                    if (num4 == 0) {
                        $("#name4").val(res.name);
                        $("#section4").val(res.section);
                        $("#phone4").val(res.phone);
                        $("#IdNumber4").val(res.card);
                        $("#job").val(res.job)
                        $("#professional").val(res.professional)
                        $("#certType4").val(res.certType)
                        form.render("select");

                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料
                                    case 0:
                                        $(`#specialContributionText`).text(item.name)
                                        $(`#specialContributionText`).attr('data-id', item.file)
                                        $(`#specialContributionText`).attr('title', item.name)
                                        if (isCloseImg) $(`#specialContributionText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#specialFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#proofText`).text(item.name)
                                        $(`#proofText`).attr('data-id', item.file)
                                        $(`#proofText`).attr('title', item.name)
                                        if (isCloseImg) $(`#proofText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#proofFile`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }
                    }else{
                        await SpecialcontributionawardAdd('1')
                        //设置数据
                        $("#name42").val(res.name);
                        $("#section42").val(res.section);
                        $("#phone42").val(res.phone);
                        $("#IdNumber42").val(res.card);
                        $("#job2").val(res.job)
                        $("#professional2").val(res.professional)
                        $("#certType42").val(res.certType)
                        form.render("select");

                        if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                            res.declareFileDOS.forEach(item => {
                                switch (Number(item.recommended)) {
                                    //0=推荐表，1=佐证材料
                                    case 0:
                                        $(`#specialContributionText2`).text(item.name)
                                        $(`#specialContributionText2`).attr('data-id', item.file)
                                        $(`#specialContributionText2`).attr('title', item.name)
                                        if (isCloseImg) $(`#specialContributionText2`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#specialFile2`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                    case 1:
                                        $(`#proofText2`).text(item.name)
                                        $(`#proofText2`).attr('data-id', item.file)
                                        $(`#proofText2`).attr('title', item.name)
                                        if (isCloseImg) $(`#proofText2`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                        $(`#proofFile2`).val(item.file)
                                        closeImgCreate()
                                        imgageClick()
                                        break;
                                }
                            })
                        }

                    }
                    break;
                case 5:
                    $("#name5").val(res.name);
                    $("#section5").val(res.section);
                    $("#phone5").val(res.phone);
                    $("#certType5").val(res.certType)
                    form.render("select");
                    if (null != res.declareFileDOS && res.declareFileDOS.length > 0) {
                        res.declareFileDOS.forEach(item => {
                            switch (Number(item.recommended)) {
                                //0=推荐表，1=佐证材料
                                case 0:
                                    $(`#employmentUnit`).text(item.name)
                                    $(`#employmentUnit`).attr('data-id', item.file)
                                    $(`#employmentUnit`).attr('title', item.name)
                                    if (isCloseImg) $(`#employmentUnit`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                    $(`#sunitFile`).val(item.file)
                                    closeImgCreate()
                                    imgageClick()
                                    break;
                                case 1:
                                    $(`#storyText`).text(item.name)
                                    $(`#storyText`).attr('data-id', item.file)
                                    $(`#storyText`).attr('title', item.name)
                                    if (isCloseImg) $(`#storyText`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                                    $(`#caseFile`).val(item.file)
                                    closeImgCreate()
                                    imgageClick()
                                    break;
                            }
                        })
                    }
                    break;
            }
            form.render("select");
        }
    }


}
//不可编辑
const notEdit = () => {
    $('#certificateList').attr("disabled", "disabled");
    $('#contacts').attr("disabled", "disabled");
    $('#position').attr("disabled", "disabled");
    $('#position1').attr("disabled", "disabled");
    $('#phone').attr("disabled", "disabled");
    $('#province').attr("disabled", "disabled");
    $('#city').attr("disabled", "disabled");
    $('#name').attr("disabled", "disabled");
    $('#name1').attr("disabled", "disabled");
    $('#section').attr("disabled", "disabled");
    $('#certificateList').attr("disabled", "disabled");
    $('#certificateList_text').attr("disabled", "disabled");
    $('#phone1').attr("disabled", "disabled");
    $('#name2').attr("disabled", "disabled");
    $('#IdNumber2').attr("disabled", "disabled");
    $('#phone2').attr("disabled", "disabled");
    $('#name3').attr("disabled", "disabled");
    $('#IdNumber3').attr("disabled", "disabled");
    $('#phone3').attr("disabled", "disabled");
    $('#name4').attr("disabled", "disabled");
    $('#name42').attr("disabled", "disabled");
    $('#job').attr("disabled", "disabled");
    $('#job2').attr("disabled", "disabled");
    $('#professional').attr("disabled", "disabled");
    $('#professional2').attr("disabled", "disabled");
    $('#section4').attr("disabled", "disabled");
    $('#section42').attr("disabled", "disabled");
    $('#phone4').attr("disabled", "disabled");
    $('#phone42').attr("disabled", "disabled");
    $('#IdNumber4').attr("disabled", "disabled");
    $('#IdNumber42').attr("disabled", "disabled");
    $('#certType4').attr("disabled", "disabled");
    $('#certType42').attr("disabled", "disabled");
    $('#name5').attr("disabled", "disabled");
    $('#section5').attr("disabled", "disabled");
    $('#phone5').attr("disabled", "disabled");
    $('#cert_typez').attr("disabled", "disabled");
    $('#cert_typey').attr("disabled", "disabled");


    $('#outstandingInternship').removeAttr("onclick");
    $('#outstandingInternship').css("background-color", "#6f5657");
    $('#outstandingInternship').css("border", "1px solid #6f5657");

    $('#outstandingInternshipdel').removeAttr("onclick");
    $('#outstandingInternshipdel').css("background-color", "#6f5657");
    $('#outstandingInternshipdel').css("border", "1px solid #6f5657");

    $('#excellentTeacherdel').removeAttr("onclick");
    $('#excellentTeacherdel').css("background-color", "#6f5657");
    $('#excellentTeacherdel').css("border", "1px solid #6f5657");

    $('#excellentWorkerdel').removeAttr("onclick");
    $('#excellentWorkerdel').css("background-color", "#6f5657");
    $('#excellentWorkerdel').css("border", "1px solid #6f5657");
    $('#excellentWorkerdel1').removeAttr("onclick");
    $('#excellentWorkerdel1').css("background-color", "#6f5657");
    $('#excellentWorkerdel1').css("border", "1px solid #6f5657");

    $('#excellentTeacher').removeAttr("onclick");
    $('#excellentTeacher').css("background-color", "#6f5657");
    $('#excellentTeacher').css("border", "1px solid #6f5657");
    $('#excellentWorker').removeAttr("onclick");
    $('#excellentWorker').css("background-color", "#6f5657");
    $('#excellentWorker').css("border", "1px solid #6f5657");
    $('#excellentWorker1').removeAttr("onclick");
    $('#excellentWorker1').css("background-color", "#6f5657");
    $('#excellentWorker1').css("border", "1px solid #6f5657");


    $('#btnsubmit').hide();

}

$(async function () {
    document.title = "关于2024年度1+X幼儿照护/产后恢复职业技能等级证书优秀单位、优秀个人和优秀案例申报的通知";
    $('.upload-me').prop('contenteditable', false);
    $('.label-me').prop('contenteditable', false);
    $('h3').prop('contenteditable', false);
    $('label').click(function(event) {
        event.stopPropagation();
        event.preventDefault();
    });
    $('.clickable').click(function(event) {
        event.stopPropagation();
        event.preventDefault();
    });
    await validateRule()
    await fromSelectChange()
    await inputNameChanges()
    await validateRuleemploymentUni()
    await butCil()
    await save()
    await selCertificateList()
    await Areainit();


    //0 = 未审核，1 = 审核通过
    if (null != declareStatus && '' != declareStatus) {
        await echo()
        if (Number(declareStatus) == 0 || Number(declareStatus) == 1) {
            await notEdit()
        } else {
            await uploadCreate('', '', '', '1')
        }
    }

});
//是否两个
let objTwo = {
    isTwo: false,
    isTwoNumber: 0,
    isTwoTrue: true
}

Object.defineProperty(objTwo, 'isTwo', {
    get: function() {
        return typeof _value === 'undefined'?false:_value;
    },
    set: function(newValue) {
        _value = newValue;
       //判断是true，加
        if(_value && objTwo.isTwoTrue){
            objTwo.isTwoTrue = false
            // SpecialcontributionawardAdd('2')
        }
    }
});
// 加入优秀组织管理奖
const SpecialcontributionawardAdd = (number)=>{
    let html=`
             <div class="Specialcontributionaward-box">
                                    <div class="layui-form-item me-from-item">
                                        <div>
                                            <label class="layui-form-label label-me clickable">姓名</label>
                                            <div class="layui-input-inline inline-me">
                                                <input type="tel" id="name42" name="name" lay-verify="required|phone"
                                                       autocomplete="off" class="layui-input" placeholder="请输入姓名">
                                            </div>
                                        </div>
                                        <div>
                                            <label class="layui-form-label label-me clickable">单位及部门</label>
                                            <div class="layui-input-inline inline-me">
                                                <input type="tel" id="section42" name="section"
                                                       lay-verify="required|phone" autocomplete="off"
                                                       class="layui-input" placeholder="请输入单位名称">
                                            </div>
                                        </div>
                                        <div>
                                            <label class="layui-form-label label-me clickable">联系方式</label>
                                            <div class="layui-input-inline inline-me">
                                                <input type="tel" id="phone42" name="phone" lay-verify="required|phone"
                                                       autocomplete="off" class="layui-input"
                                                       placeholder="请输入联系方式">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item me-from-item">
                                        <div>
                                            <label class="layui-form-label label-me clickable">证书类别</label>
                                            <div class="layui-input-inline inline-me">
                                                <select name="certType" id="certType42" class="layui-input"  lay-filter="certy12"
                                                        placeholder="请选择一个证书类别">
                                                    <option value="">请选择一个证书类别</option>
                                                    <option value="1">幼儿照护</option>
                                                    <option value="2">产后恢复</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div>
                                            <label class="layui-form-label label-me clickable">职务</label>
                                            <div class="layui-input-inline inline-me">
                                                <input type="tel" id="job2" name="job" lay-verify="required|phone"
                                                       autocomplete="off" class="layui-input" placeholder="请输入职务">
                                            </div>
                                        </div>
                                        <div>
                                            <label class="layui-form-label label-me clickable">职称</label>
                                            <div class="layui-input-inline inline-me">
                                                <input type="tel" id="professional2" name="professional"
                                                       lay-verify="required|phone" autocomplete="off"
                                                       class="layui-input" placeholder="请输入职称">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item" style="display: flex;">
                                        <div>
                                            <label class="layui-form-label label-me clickable">身份证号码</label>
                                            <div class="layui-input-inline inline-me">
                                                <input type="tel" id="IdNumber42" name="card" lay-verify="required|phone"
                                                       autocomplete="off" class="layui-input"
                                                       placeholder="请输入身份证号码">
                                            </div>
                                        </div>
                                        <div>
                                            <label class="layui-form-label label-me clickable">优秀组织管理推荐表</label>
                                            <div class="layui-input-inline inline-me">
                                                <button class="layui-btn btn-colorslick" style="margin-bottom: 10px"
                                                        onclick="DownloadCreate('specialFile')">下载模板
                                                </button>
                                                <div id="specialContributionUpload2" class="upload-me"
                                                     style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p class="clickable">点击上传</p>
                                                        <input type="text" style="opacity:0;width: 0px;"
                                                               id="specialFile2"
                                                               name="specialFile"/>
                                                    </div>
                                                </div>
                                                <div class="textUpload" id="specialContributionText2"
                                                     style="margin-top: 10px">

                                                </div>
                                            </div>
                                        </div>
                                        <div>
                                            <label class="layui-form-label label-me clickable">佐证材料</label>
                                            <div class="layui-input-inline inline-me">
                                                <button class="layui-btn btn-colorslick" style="margin-bottom: 10px"
                                                        onclick="DownloadCreate('proofFile')">下载模板
                                                </button>
                                                <div id="proofUpload2" class="upload-me" style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p class="clickable">点击上传</p>
                                                        <input type="text" style="opacity:0;width: 0px;" id="proofFile2"
                                                               name="proofFile"/>
                                                    </div>
                                                </div>
                                                <div class="textUpload" id="proofText2" style="margin-top: 10px">

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
            `
    $('.Specialcontributionaward').append(html)
    form.render('select');
    fromSelectChange()
    butCil()
    console.log('===加=')
    if(number==='2'){
        uploadCreate('specialContributionUpload2', 'specialContributionText2', 'specialFile2', number)
        uploadCreate('proofUpload2', 'proofText2', 'proofFile2', number)
    }
    console.log('>>>>bumber',number,number==='2')
}
function inputNameChanges() {
    $('#name2').on('change',async function (e){
        let res = await verifyCreate()
        if(res.data === "1" || res.data === null || res.data === 'null') {
            objTwo.isTwo=false
            if($(this).val() !=="") {
                $('#name3').prop('disabled', true);
                $('#IdNumber3').prop('disabled', true);
                $('#phone3').prop('disabled', true);
                $('#cert_typey').prop('disabled', true); // 禁用下拉框的选择
                $('#TeachersUpload').addClass('disabled')
                $('#trainUpload').addClass('disabled')
                layer.msg('试点院校可推荐1名优秀培训教师或1名优秀考务工作者（考务工作者包括考务人员、技术员、考评员、督导员）');
            }else {
                $('#name3').prop('disabled', false);
                $('#IdNumber3').prop('disabled', false);
                $('#phone3').prop('disabled', false);
                $('#cert_typey').prop('disabled', false);
                $('#TeachersUpload').removeClass('disabled')
                $('#trainUpload').removeClass('disabled')
            }
            form.render('select');
        }else if(res.data === "2" || res.data === 2) {
            objTwo.isTwo=true
            if($(this).val() !==""){
                objTwo.isTwoNumber++;
            }else{
                objTwo.isTwoNumber--;
            }
            console.log('当前', $(this).val() !=="", objTwo.isTwoNumber)
            layer.msg('试点院校可推荐2名优秀培训教师或2名优秀考务工作者或1名优秀培训教师和1名优秀考务工作者（考务工作者包括考务人员、技术员、考评员、督导员）');
        }
    })

    $('#name3').on('change',async function (){
        let res = await verifyCreate()
        if(res.data === "1" || res.data === null || res.data === 'null') {
            objTwo.isTwo=false
            if($(this).val() !=="") {
                $('#name2').prop('disabled', true);
                $('#card').prop('disabled', true);
                $('#phone2').prop('disabled', true);
                $('#cert_typez').prop('disabled', true);
                $('#TeacherUpload').addClass('disabled')
                $('#outstandingUpload').addClass('disabled')
                layer.msg('试点院校可推荐1名优秀培训教师或1名优秀考务工作者（考务工作者包括考务人员、技术员、考评员、督导员）');
            }else {
                $('#name2').prop('disabled', false);
                $('#card').prop('disabled', false);
                $('#phone2').prop('disabled', false);
                $('#cert_typez').prop('disabled', false);
                $('#TeacherUpload').removeClass('disabled')
                $('#outstandingUpload').removeClass('disabled')
            }
            form.render('select');
        }else if(res.data === "2" || res.data === 2) {
            objTwo.isTwo=true
            if($(this).val() !==""){
                objTwo.isTwoNumber++;
            }else{
                objTwo.isTwoNumber--;
            }
            console.log('当前', $(this).val() !=="", objTwo.isTwoNumber)
            layer.msg('试点院校可推荐2名优秀培训教师或2名优秀考务工作者或1名优秀培训教师和1名优秀考务工作者（考务工作者包括考务人员、技术员、考评员、督导员）');
        }
    })

    $('#IdNumber2').on('change',async function (e){
        let res = await verifyCreate()
        if(res.data === "1" || res.data === null || res.data === 'null') {
            if($(this).val() !=="") {
                $('#name3').prop('disabled', true);
                $('#IdNumber3').prop('disabled', true);
                $('#phone3').prop('disabled', true);
                $('#cert_typey').prop('disabled', true); // 禁用下拉框的选择
                $('#TeachersUpload').addClass('disabled')
                $('#trainUpload').addClass('disabled')
            }else {
                $('#name3').prop('disabled', false);
                $('#IdNumber3').prop('disabled', false);
                $('#phone3').prop('disabled', false);
                $('#cert_typey').prop('disabled', false);
                $('#TeachersUpload').removeClass('disabled')
                $('#trainUpload').removeClass('disabled')
            }
            form.render('select');
        }
    })

    $('#IdNumber3').on('change',async function (){
        let res = await verifyCreate()
        if(res.data === "1" || res.data === null || res.data === 'null') {
            if($(this).val() !=="") {
                $('#name2').prop('disabled', true);
                $('#card').prop('disabled', true);
                $('#phone2').prop('disabled', true);
                $('#cert_typez').prop('disabled', true);
                $('#TeacherUpload').addClass('disabled')
                $('#outstandingUpload').addClass('disabled')
            }else {
                $('#name2').prop('disabled', false);
                $('#card').prop('disabled', false);
                $('#phone2').prop('disabled', false);
                $('#cert_typez').prop('disabled', false);
                $('#TeacherUpload').removeClass('disabled')
                $('#outstandingUpload').removeClass('disabled')
            }
            form.render('select');
        }
    })

    $('#phone2').on('change',async function (e){
        let res = await verifyCreate()
        if(res.data === "1" || res.data === null || res.data === 'null') {
            if($(this).val() !=="") {
                $('#name3').prop('disabled', true);
                $('#IdNumber3').prop('disabled', true);
                $('#phone3').prop('disabled', true);
                $('#cert_typey').prop('disabled', true); // 禁用下拉框的选择
                $('#TeachersUpload').addClass('disabled')
                $('#trainUpload').addClass('disabled')
            }else {
                $('#name3').prop('disabled', false);
                $('#IdNumber3').prop('disabled', false);
                $('#phone3').prop('disabled', false);
                $('#cert_typey').prop('disabled', false);
                $('#TeachersUpload').removeClass('disabled')
                $('#trainUpload').removeClass('disabled')
            }
            form.render('select');
        }
    })

    $('#phone3').on('change',async function (){
        let res = await verifyCreate()
        if(res.data === "1" || res.data === null || res.data === 'null') {
            if($(this).val() !=="") {
                $('#name2').prop('disabled', true);
                $('#card').prop('disabled', true);
                $('#phone2').prop('disabled', true);
                $('#cert_typez').prop('disabled', true);
                $('#TeacherUpload').addClass('disabled')
                $('#outstandingUpload').addClass('disabled')
            }else {
                $('#name2').prop('disabled', false);
                $('#card').prop('disabled', false);
                $('#phone2').prop('disabled', false);
                $('#cert_typez').prop('disabled', false);
                $('#TeacherUpload').removeClass('disabled')
                $('#outstandingUpload').removeClass('disabled')
            }
            form.render('select');
        }
    })



    $('#certificateList').on('change',function () {
        $('#excellenTeacherSignupForm')[0].reset()
        $('#ExcellentexaminationworkerSignupForm')[0].reset()
    })
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $.validator.addMethod("phone", function (value, element) {
        var phoneRegex = /^\d+$/; // 只接受数字的正则表达式
        if (this.optional(element) || !phoneRegex.test(value)) {
            return false; // 如果手机号为空或不符合格式，直接返回错误
        }
        var chinaPhoneRegex = /^1[3-9]\d{9}$/; // 中国大陆手机号格式正则表达式
        return chinaPhoneRegex.test(value); // 检查手机号是否符合中国大陆格式
    }, "请输入有效的手机号");
    $.validator.addMethod("notEmpty", function(value, element) {
        return $.trim(value) !== "";
    }, "该字段不能为空");

    $("#signupForm").validate({
        rules: {
            orgName: {
                required: true
            },
            contacts: {
                required: true
            },
            position: {
                required: true
            },
            place: {
                required: true
            },
            phone: {
                required: true,
                phone: true // 应用自定义的手机号验证规则
            },
            province: {
                required: true
            },
            city: {
                notEmpty: true
            },
        }
    })
}

function validateRuleemploymentUni() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#employmentUniSignupForm").validate({
        rules: {
            name: {
                required: true
            },
            section: {
                required: true
            },
            phone: {
                required: true
            },
        }
    })
}

function closeImgCreate() {
    $('.closeImg').on('click', function (e) {
        var parentElement = $(e.target).parent();
        //去掉input
       let myfile=$(e.target).parent().parent().find("input")
        myfile.map(item=>{
            $(myfile[item]).val('')
        })
        // 清空文本内容
        parentElement.text('');

        // 清空标题
        parentElement.removeAttr('title');
        parentElement.removeAttr('data-id');
        // 删除data-id属性
        parentElement.removeData('id');
        // 删除data-id属性
        // 同时修改data-id属性的值为空字符串
        parentElement.attr('data-id', '');
        // 移除所有子元素
        parentElement.children().remove();
        e.stopPropagation();
        e.preventDefault();
    });
}

function imgageClick() {
    $('.textUpload').on('click', function (e) {

        e.stopPropagation();
        e.preventDefault();
        let url = $(this).data('id')
        console.log($(this).data('id'))
        $('.overlays img').attr('src', '')
        var parts = url.split('.');
        var lastPart = parts[parts.length - 1];
        switch (lastPart.toUpperCase()) {
            case 'JPEG':
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'JPG':
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'PNG':
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'GIF':
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'BMP':
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'SVG':
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'WEBP':
                console.log('11')
                $('.overlays').addClass('active');
                $('.overlays img').attr('src', url);
                return;
            case 'PDF':
                window.open(url)
                return;
            case 'MP4':
                window.open(url)
                return;
        }

        window.location.href = url
    });
    $('.overlays').click(function () {
        $(this).removeClass('active');
    });
}

function butCil() {
    $('button').click(function (event) {
        event.stopPropagation();
        event.preventDefault();
        event.preventDefault(); // 取消按钮的默认行为
    });
}

//单位名称
function selCertificateList() {
    $('#certificateList').selectPage({
        showField: 'name',
        // showField: 'schoolName',
        keyField: 'id',
        searchField: 'name',
        // searchField: 'schoolName',
        data: '/jzweb/declare/selectSchool',
        // data: '/jzweb/archives/list',
        //向服务端提交的参数中，增加已选中的
        //设置返回-1，意为通知服务端返回空列表，初始化时使用
        params: function () {
            var pv = $('#certificateList').val();
            return pv;
        },
        eAjaxSuccess: function (d) {
            var result;
            if (d) result = d.data;
            else result = undefined;
            return result;
            add.js
        },
    });
}

function uploadCreate(doms, text, file, type) {
    layui.use('upload', function () {
        var upload = layui.upload;

        // 自定义切片上传组件
        function ChunkUploader(elemId, textId, textInput) {
            this.elemId = elemId;
            this.textId = textId
            this.textInput = textInput
            this.initUploader();
        }

        ChunkUploader.prototype.initUploader = function () {
            var self = this;
            upload.render({
                elem: '#' + self.elemId,
                url: '/common/sysFile/uploadFileOssDeclare',
                accept: 'file',
                size: 200 * 1024, // 限制文件大小为 200MB
                before: function(obj) {
                    // 在上传之前执行数据验证逻辑
                    if (!$('#certificateList').val()) {
                        layer.msg('请选择单位名称后在进行上传');
                        return false; // 阻止上传
                    }
                    this.data = {
                        name: $('#certificateList_text').val()
                    }
                },
                done: function (res) {
                    if (res.code === '0') {
                        if (!$('#certificateList').val()) return;
                        let value = res.data.substring(res.data.lastIndexOf('/') + 1);
                        $(`#${self.textId}`).text(value)
                        $(`#${self.textId}`).attr('data-id', res.data)
                        $(`#${self.textId}`).attr('title', value)
                        $(`#${self.textId}`).append(`<img style="width: 20px;height: 20px" class="closeImg" src="/img/close.png"></img>`)
                        $(`#${self.textInput}`).val(res.data)
                        closeImgCreate()
                        imgageClick()
                        return
                    }
                    // layer.msg(res.msg);
                },
                error: function (e) {
                    //请求异常回调
                    // layer.msg(e);
                },

            });
        };
        if (type === '1') {
            var uploader1 = new ChunkUploader('employmentsUnitUpload', 'employmentUnits', 'jobFile');
            var uploader1 = new ChunkUploader('storysBtnUpload', 'storysText', 'introFile');
            var uploader1 = new ChunkUploader('vidoeBtnUpload', 'videoText', 'videoFile');
            var uploader1 = new ChunkUploader('TeacherUpload', 'teachertext', 'TeacherFile');
            var uploader1 = new ChunkUploader('outstandingUpload', 'outstandingText', 'outstandingFile');
            var uploader1 = new ChunkUploader('TeachersUpload', 'Teacherstext', 'TeachersFile');
            var uploader1 = new ChunkUploader('trainUpload', 'trainText', 'trainFile');
            var uploader1 = new ChunkUploader('specialContributionUpload', 'specialContributionText', 'specialFile');
            var uploader1 = new ChunkUploader('proofUpload', 'proofText', 'proofFile');
            var uploader1 = new ChunkUploader('specialContributionUpload2', 'specialContributionText2', 'specialFile2')
            var uploader1 = new ChunkUploader('proofUpload2', 'proofText2', 'proofFile2')
            var uploader1 = new ChunkUploader('employmentUnitUpload', 'employmentUnit', 'sunitFile');
            var uploader1 = new ChunkUploader('storyBtnUpload', 'storyText', 'caseFile');
        } else {
            var uploader1 = new ChunkUploader(doms, text, file);
        }


    });

}


const sxDOMS = async () => {
    let classNameText = `${'employmentsUnitUpload' + flag1}`
    let classNameAdd = `${'employmentUnits' + flag1}`
    let tiles = `${'jobFile' + flag1}`
    let classNameTexttow = `${'storysBtnUpload' + flag1}`
    let classNameAddrow = `${'storysText' + flag1}`
    let tilestow = `${'introFile' + flag1}`
    let classNameTextthree = `${'vidoeBtnUpload' + flag1}`
    let classNameAddthree = `${'textUpload' + flag1}`
    let tilestowthree = `${'videoFile' + flag1}`
    let arr = `
    <div class="employmentUnitDoms-box">
        <div class="layui-form-item me-from-item">
            <div style="display:flex;">
               <label class="layui-form-label label-me" >法定联系人</label>
                    <div class="layui-input-inline inline-me" >
                    <input type="tel" name="name" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入法定联系人">
               </div>
            </div>
            <div style="display:flex;">
                 <label class="layui-form-label label-me" >单位名称</label>
                     <div class="layui-input-inline inline-me" >
                         <input type="tel" name="section" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入单位名称">
                     </div>
            </div>
            <div style="display:flex;">
                     <label class="layui-form-label label-me">联系方式</label>
                     <div class="layui-input-inline inline-me" >
                         <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入联系方式">
                     </div>
            </div>
        </div>
        <div class="layui-form-item me-from-item">
            <div style="display:flex;">
                 <label class="layui-form-label label-me clickable">证书类别</label>
                 <div class="layui-input-inline inline-me">
                     <select name="certType" class="layui-input" placeholder="请选择一个证书类别">
                         <option value="">请选择一个证书类别</option>
                         <option value="1">幼儿照护</option>
                         <option value="2">产后恢复</option>
                     </select>
                 </div>
            </div> 
        </div>    
        <div class="layui-form-item me-from-item">
            <div style="display:flex;">
                <label class="layui-form-label label-me">就业单位推荐表</label>
                <div class="layui-input-inline inline-me">
                    <button type="submit" class="layui-btn btn-colorslick" style="margin-bottom: 10px" onclick="DownloadCreate('jobFile')">下载模板</button>
                    <div id="${classNameText}" style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p >点击上传</p>
                                <input type="text" style="opacity:0;width: 0px;" id="${tiles}"
                                       name="${tiles}"/>
                        </div>
                    </div>
                    <div class="textUpload" id="${classNameAdd}" style="margin-top: 10px;"></div>
                </div>
            </div>
            <div style="display:flex;">
                <label class="layui-form-label label-me">就业情况简介与典型事迹</label>
                <div  class="layui-input-inline inline-me">
                    <button class="layui-btn btn-colorslick" style="margin-bottom: 10px" onclick="DownloadCreate('introFile')">下载模板</button>
                    <div id="${classNameTexttow}" style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p >点击上传</p>
                                <input type="text" style="opacity:0;width: 0px;" id="${tilestow}"
                                       name="${tilestow}"/>
                        </div>
                    </div>
                    <div  class="textUpload"  id="${classNameAddrow}" style="margin-top: 10px">

                    </div>
                </div>
            </div>
            <div style="display:flex;">
                <label class="layui-form-label label-me">就业学生视频：</label>
                <div class="layui-input-inline inline-me">
                    <div id="${classNameTextthree}" style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p >点击上传</p>
                                <input type="text" style="opacity:0;width: 0px;" id="${tilestowthree}"
                                       name="${tilestowthree}"/>
                        </div>
                    </div>
                    <div  class="textUpload"  id="${classNameAddthree}" style="margin-top: 10px">

                    </div>
                </div>
            </div>
        </div>
    </div>
    `
    $('.employmentUnitDoms').append(arr)
    form.render('select');
    await butCil()
    if (practiceClick1) await uploadCreate(classNameText, classNameAdd, tiles, '2')
    if (practiceClick1) await uploadCreate(classNameTexttow, classNameAddrow, tilestow, '2')
    if (practiceClick1) await uploadCreate(classNameTextthree, classNameAddthree, tilestowthree, '2')

}


function teacherDOMS() {
    let classNameText = `${'TeacherUpload' + flag2}`
    let classNameAdd = `${'teachertext' + flag2}`
    let tiles = `${'TeacherFile' + flag2}`
    let classNameTexttow = `${'outstandingUpload' + flag2}`
    let classNameAddrow = `${'outstandingText' + flag2}`
    let tilestow = `${'outstandingFile' + flag2}`
    let arr = `
         <div class="excellenTeacherDoms-box">
            <div class="layui-form-item me-from-item">
                <div>
                    <label class="layui-form-label label-me">姓名</label>
                    <div class="layui-input-inline inline-me">
                        <input type="tel" name="name" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入姓名">
                    </div>
                </div>
                <div>
                    <label class="layui-form-label label-me">身份证号码</label>
                    <div class="layui-input-inline inline-me">
                        <input type="tel" name="card" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入身份证号码">
                    </div>
                </div>
                <div>
                    <label class="layui-form-label label-me">联系方式</label>
                    <div class="layui-input-inline inline-me">
                        <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入联系方式">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="display: flex;">
               <div>
                  <label class="layui-form-label label-me">证书类别</label>
                  <div class="layui-input-inline inline-me">
                      <select name="certType" id="${'cert_typez' + flag2 }" lay-filter="${'certz' + flag2 }"  class="layui-input" placeholder="请选择一个证书类别">
                          <option value="">请选择一个证书类别</option>
                          <option value="1">幼儿照护</option>
                          <option value="2">产后恢复</option>
                      </select>
                  </div>
               </div>
               <div>
                   <label class="layui-form-label label-me">教师推荐表</label>
                   <div class="layui-input-inline inline-me">
                       <button class="layui-btn btn-colorslick" style="margin-bottom: 10px" onclick="DownloadCreate('teacherFile')">下载模板</button>
                       <div id="${classNameText}" style="width: 10%;">
                                   <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                       <img src="/img/组 34@2x.png">
                                       <p >点击上传</p>
                               <input type="text" style="opacity:0;width: 0px;" id="${tiles}"
                                      name="${tiles}"/>
                           </div>
                       </div>
                       <div class="textUpload"  id="${classNameAdd}" style="margin-top: 10px">

                       </div>
                   </div>
               </div>
               <div>
                 <label class="layui-form-label label-me">证书培训经历与优秀事迹</label>
                  <div class="layui-input-inline inline-me">
                      <button  class="layui-btn btn-colorslick" style="margin-bottom: 10px" onclick="DownloadCreate('trainFile')">下载模板</button>
                      <div id="${classNameTexttow}" style="width: 10%;">
                                   <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                      <img src="/img/组 34@2x.png">
                                      <p >点击上传</p>
                              <input type="text" style="opacity:0;width: 0px;" id="${tilestow}"
                                     name="${tilestow}"/>
                          </div>
                      </div>
                      <div class="textUpload"  id="${classNameAddrow}" style="margin-top: 10px">

                      </div>
                      </div>
                      </div>
               </div>
       </div>
    `
    $('.excellenTeacherDoms').append(arr)
    form.render('select');
    fromSelectChange()
    butCil()
    if(restrictPracticeClick1) uploadCreate(classNameText, classNameAdd, tiles, '2')
    if(restrictPracticeClick1) uploadCreate(classNameTexttow, classNameAddrow, tilestow, '2')

}

function outstandingDoms() {
    let classNameText = `${'TeachersUpload' + flag3}`
    let classNameAdd = `${'Teacherstext' + flag3}`
    let tiles = `${'TeachersFile' + flag3}`
    let classNameTexttow = `${'trainUpload' + flag3}`
    let classNameAddrow = `${'trainText' + flag3}`
    let tilestow = `${'trainFile' + flag3}`
    let arr = `
                      <div class="Excellentexaminationworker-box">
                                <div class="layui-form-item me-from-item">
                                    <div>
                                        <label class="layui-form-label label-me">姓名</label>
                                        <div class="layui-input-inline inline-me">
                                            <input type="tel" name="name" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入姓名">
                                        </div>
                                    </div>
                                    <div>
                                        <label class="layui-form-label label-me">身份证号码</label>
                                        <div class="layui-input-inline inline-me">
                                            <input type="tel" name="card" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入身份证号码">
                                        </div>
                                    </div>
                                    <div>
                                        <label class="layui-form-label label-me">联系方式</label>
                                        <div class="layui-input-inline inline-me">
                                            <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入联系方式">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="display: flex;">
                                  <div>
                                      <label class="layui-form-label label-me">证书类别</label>
                                      <div class="layui-input-inline inline-me">
                                          <select name="certType" id="${'cert_typez' + flag3}" lay-filter="${'certy' + flag3}"  class="layui-input" placeholder="请选择一个证书类别">
                                              <option value="">请选择一个证书类别</option>
                                              <option value="1">幼儿照护</option>
                                              <option value="2">产后恢复</option>
                                          </select>
                                      </div>
                                   </div>
                                    <div>
                                        <label class="layui-form-label label-me">教师推荐表</label>
                                        <div class="layui-input-inline inline-me">
                                            <button class="layui-btn btn-colorslick" style="margin-bottom: 10px" onclick="DownloadCreate('workerFile')">下载模板</button>
                                            <div id="${classNameText}" style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p >点击上传</p>
                                                    <input type="text" style="opacity:0;width: 0px;" id="${tiles}"
                                                           name="${tiles}"/>
                                                </div>
                                            </div>
                                            <div class="textUpload"  id="${classNameAdd}" style="margin-top: 10px">

                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <label class="layui-form-label label-me">组考督导经历与优秀事迹</label>
                                        <div class="layui-input-inline inline-me">
                                            <button  class="layui-btn btn-colorslick" style="margin-bottom: 10px" onclick="DownloadCreate('storyFile')">下载模板</button>
                                            <div id="${classNameTexttow}" style="width: 10%;">
                                                    <div style="border: 1px dashed #dedede;width: 90px;height: 90px;text-align: center">
                                                        <img src="/img/组 34@2x.png">
                                                        <p >点击上传</p>
                                                    <input type="text" style="opacity:0;width: 0px;" id="${tilestow}"
                                                           name="${tilestow}"/>
                                                </div>
                                            </div>
                                            <div class="textUpload"  id="${classNameAddrow}" style="margin-top: 10px">

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
    `
    $('.Excellentexaminationworker').append(arr)
    form.render('select');
    fromSelectChange()
    butCil()
    if(restrictPracticeClick2) uploadCreate(classNameText, classNameAdd, tiles, '2')
    if(restrictPracticeClick2) uploadCreate(classNameTexttow, classNameAddrow, tilestow, '2')

}


//新增
const practiceClick = async (dom, delBtn, type) => {
    var elements = $(`.${dom}`).children().length;
    if (elements === 3) return

    if (type === 1) {
        await sxDOMS()
        flag1++
    }
    if (type === 2) {
            await teacherDOMS()
            flag2++
    }
    if (type === 3) {
        await outstandingDoms()
        flag3++
    }
    $(`#${delBtn}`).show()


}

async function restrictPracticeClick(dom, delBtn, type) {
    let names = $('#certificateList').val()
    if (names === '') {
        layer.msg('请选择申报主体单位名称');
        return;
    }
    const r = await verifyCreate()

    if (r.code === '1') return layer.msg(r.msg)
    if (r.data === 1) return
    var elements = $(`.${dom}`).children().length;
    if (elements === 2) return

    if (type === 1) {
        await sxDOMS()
        $(`#${delBtn}`).show()
        flag1++
    }
    if (type === 2) {
        //优秀培训教师
        if(objTwo.isTwoNumber<2 || !objTwo.isTwo) {
            objTwo.isTwoNumber++;
            if (certificateNum * 1 >= 2) {
                if (flag3 >= 2) return
                await teacherDOMS()
                $(`#${delBtn}`).show()
                $('#Excellent-examination-worker').hide()
                $('#ExcellentexaminationworkerSignupForm')[0].reset();
                $('#Teacherstext').text('')
                $('#trainText').text('')
                flag2++
            }
        }

    }
    if (type === 3) {
        if(objTwo.isTwoNumber<2 || !objTwo.isTwo) {
            objTwo.isTwoNumber++;
            if (certificateNum * 1 >= 2) {
                if (flag2 >= 2) return
                await outstandingDoms()
                $(`#${delBtn}`).show()
                $('#Excellent-training-teacher').hide()
                $('#excellenTeacherSignupForm')[0].reset();
                $('#teachertext').text('')
                $('#outstandingText').text('')
                flag3++
            }
        }

    }
    if (type === 4) {
        SpecialcontributionawardAdd('2')
        $(`#${delBtn}`).show()
    }
}

// 删除
function practiceDel(dom, delBtn, type) {
    let index = layer.confirm('是否删除当前推荐？', {
        btn: ['确定', '取消']
    }, async function () {
        var elements = $(`.${dom}`);
        var count = elements.children().length;



        if (count !== 1) {
            elements.children().last().remove()
            if (elements.children().length === 1) {
                $(`#${delBtn}`).hide()
            }
            if (type === 1) {
                flag1--
            }
            if (type === 2) {
                flag2--
                $('#cert_typez').val('');
                $('#cert_typez1').val('');
                $('#Excellent-examination-worker').show()
                $('#ExcellentexaminationworkerSignupForm')[0].reset();
                $('#Teacherstext').text('')
                $('#trainText').text('')
                //删除
                if(objTwo.isTwo) {
                    objTwo.isTwoNumber--;
                    console.log('删除', objTwo.isTwoNumber)
                }
            }
            if (type === 3) {
                flag3--
                $('#cert_typey').val('');
                $('#cert_typey1').val('');
                $('#Excellent-training-teacher').show()
                $('#excellenTeacherSignupForm')[0].reset();
                $('#teachertext').text('')
                $('#outstandingText').text('')
                //删除
                if(objTwo.isTwo) {
                    objTwo.isTwoNumber--;
                    console.log('删除', objTwo.isTwoNumber)
                }
            }
            if (type === 4) {

            }
        } else {
            $(`#${delBtn}`).hide()
        }
        layer.close(index);
    })

}

function save() {
    $.ajax({
        type: "get",
        url: `/jzweb/declareReady/selectDeclareReadyById?id=${resourceId}`,
        success: function (data) {
            if (data.code === '0') {
                datas = data.data
                document.getElementById("titleText").innerHTML = datas.remark
                $('#headerImg').attr('src', datas.img)
                $('#alink').html(`<a href="javascript:" style="color: #02a7f0" data-id="${datas.reportFile}" onclick="titleClicks(datas.reportFile)">${datas.reportFile.substring(datas.reportFile.lastIndexOf('/') + 1).substring(32)}</a>`)
            } else {
                layer.close(data.msg);
            }

        }
    });

}

function titleClicks(url) {
    window.open(url)
}

// 下载
function DownloadCreate(type) {
    let url = ''
    url = datas[`${type}`]
    if (url === '' || url === 'null' || url === null) return layer.msg('暂无模板')
    window.location.href = url
}

function fromSelectChange() {
    layui.use(['form'], function(){
        var form = layui.form;
        form.on('select', function(data) {
            var layFilter = data.elem.getAttribute('lay-filter')
            console.log('layFilterlayFilterlayFilterlayFilter', layFilter)
            if(layFilter === 'certy11'){
                var select1Value = data.value;
                if (select1Value === '1') {
                    $('#certType42').val('2');
                } else {
                    $('#certType42').val('1');
                }
            }else if(layFilter === 'certy12'){
                var select1Value = data.value;
                if (select1Value === '1') {
                    $('#certType4').val('2');
                } else {
                    $('#certType4').val('1');
                }
            }
            if (layFilter === 'certy') { // 如果选择了第一个 select 组件
                var select1Value = data.value;
                if (select1Value === '1') {
                    $('#cert_typez').val('2');
                } else {

                    $('#cert_typez').val('1');
                }
            } else if (layFilter === 'certz') { // 如果选择了第二个 select 组件
                var select2Value = data.value;
                if (select2Value === '1') {
                    console.log('1')
                    // 设置第一个 select 组件的选中值为 'option2'
                    $('#cert_typey').val('2');
                    // $('#cert_typey option:nth-child(2)').prop('disabled', true);
                } else {
                    console.log('2')
                    // 设置第一个 select 组件的选中值为 ''
                    $('#cert_typey').val('1');
                    // $('#cert_typey option:nth-child(3)').prop('disabled', true);
                }
            }
            if (layFilter === 'certy') { // 如果选择了第一个 select 组件
                var select1Value = data.value;
                if (select1Value === '1') {
                    // 设置第二个 select 组件的选中值为 'option2'
                    $('#cert_typey1').val('2');
                    $('#cert_typez1').val('2');
                    // $('#cert_typey1 option:nth-child(2)').prop('disabled', true);
                } else {
                    // 设置第二个 select 组件的选中值为 ''
                    $('#cert_typey1').val('1');
                    $('#cert_typez1').val('1');
                    // $('#cert_typey1 option:nth-child(3)').prop('disabled', true);
                }
            } else if (layFilter === 'certy1') { // 如果选择了第二个 select 组件
                var select2Value = data.value;

                if (select2Value === '1') {
                    // 设置第一个 select 组件的选中值为 'option2'
                    $('#cert_typey').val('2');
                    // $('#cert_typey option:nth-child(2)').prop('disabled', true);
                } else {
                    // 设置第一个 select 组件的选中值为 ''
                    $('#cert_typey').val('1');
                    // $('#cert_typey option:nth-child(3)').prop('disabled', true);
                }
            }
            if (layFilter === 'certz') { // 如果选择了第一个 select 组件
                var select1Value = data.value;
                if (select1Value === '1') {
                    // 设置第二个 select 组件的选中值为 'option2'
                    $('#cert_typez1').val('2');
                    // $('#cert_typez1 option:nth-child(2)').prop('disabled', true);
                } else {
                    // 设置第二个 select 组件的选中值为 ''
                    $('#cert_typez1').val('1');
                    // $('#cert_typez1 option:nth-child(3)').prop('disabled', true);
                }
            } else if (layFilter === 'certz1') { // 如果选择了第二个 select 组件
                var select2Value = data.value;

                if (select2Value === '1') {
                    // 设置第一个 select 组件的选中值为 'option2'
                    $('#cert_typez').val('2');
                    // $('#cert_typez option:nth-child(2)').prop('disabled', true);
                } else {
                    // 设置第一个 select 组件的选中值为 ''
                    $('#cert_typez').val('1');
                    // $('#cert_typez option:nth-child(3)').prop('disabled', true);
                }
            }
            form.render('select');
        });
    });
}

async function submitClick() {
    if ($('#certificateList').val() === '') {
        layer.msg('请选择单位名称')
        return
    }
    if ($('#city').val() === '') {
        layer.msg('请选择所属市')
        return
    }
    if (!$("#signupForm").valid()) {
        return
    }
    if ($('#province').val() === '') {
        layer.msg('请选择所属省份')
        return
    }

    if(!await inputIntegrity()) return
    const list = await verifyCreate()
    if (list.code === '1') {
        if ($('.excellenTeacherDoms').children().length !== 1) {
            $('.excellenTeacherDoms').children().last().remove();
            $(`#excellentTeacherdel`).hide()
        }
        if ($('.Excellentexaminationworker').children().length !== 1) {
            $('.Excellentexaminationworker').children().last().remove();
            $(`#excellentWorkerdel`).hide()
        }
        if ($('.Specialcontributionaward').children().length !== 1) {
            $('.Specialcontributionaward').children().last().remove();
            $(`#excellentWorkerdel1`).hide()
        }

    }
    if (flag) {
        layer.msg('正在提交，请稍等......')
        return
    }
    let titleDate = {
        declareTypeDOS: []
    }
    $.each($('#signupForm').serializeArray(), function (index, field) {
        titleDate[field.name] = field.value;
        console.log(field)
        if (field.name === 'orgName') {
            titleDate['orgId'] = field.value;
        }
    });
    titleDate.orgName = titleDate.orgName_text
    delete titleDate.orgName_text
    let practice = $('#employmentUniSignupForm').serializeArray()
    let Teacher = $('#excellenTeacherSignupForm').serializeArray()
    let outstanding = $('#ExcellentexaminationworkerSignupForm').serializeArray()
    let specialContribution = $('#Specialcontributionaward').serializeArray()
    let excellentCase = $('#Excellentcase').serializeArray()
    let a = await dataCreate(practice, 7, '1')
    let b = await dataCreate(Teacher, 6, '2')
    let c = await dataCreate(outstanding, 6, '3')
    let d = await dataCreate(specialContribution, 9, '4')
    let e = await dataCreate(excellentCase, 7, '5')
    var hasNameField = c.some(function(obj) {
        return obj.hasOwnProperty('name');
    });
    if (!hasNameField) {
        c = []
    }
    titleDate.declareTypeDOS = [...a, ...b, ...c, ...d, ...e]
    titleDate['declareReadyId'] = datas?.id
    declareCreate(titleDate)
}


// 参数校验
async function inputIntegrity() {
    let flag = false
    let practice = $('#employmentUniSignupForm').serializeArray()
    let Teacher = $('#excellenTeacherSignupForm').serializeArray()
    let outstanding = $('#ExcellentexaminationworkerSignupForm').serializeArray()
    let specialContribution = $('#Specialcontributionaward').serializeArray()
    let excellentCase = $('#Excellentcase').serializeArray()

    let practiceFlag = await checkObjects(practice,'value')
    let TeacherFlag =  await checkObjects(Teacher,'value')
    let outstandingFlag =  await checkObjects(outstanding,'value')
    let specialContributionFlag = await checkObjects(specialContribution,'value')
    let excellentCaseFlag =  await checkObjects(excellentCase,'value')


    if(practiceFlag || TeacherFlag || outstandingFlag || specialContributionFlag || excellentCaseFlag) {
        flag = true
    } else {
        layer.msg('请将数据填写完整');
        flag = false
    }
    return flag
}

function checkObjects(arr, propName) {
    const hasValue = arr.some(obj => Boolean(obj[propName]));
    if (!hasValue) {
        return true;
    } else {
        const allHaveValue = arr.every(obj => Boolean(obj[propName]));
        return allHaveValue;
    }
}

function dataCreate(dataValue, nub, typeValue) {
    var list = []
    var chunkSize = nub; // 定义每个分块的大小
    console.log('dataValue.lengthdataValue.length', dataValue.length)
    for (var i = 0; i < dataValue.length; i += chunkSize) {
        var data = {
            declareFileDOS: []
        };
        var chunk = dataValue.slice(i, i + chunkSize); // 获取当前分块的对象

        // 在这里对当前分块的对象进行处理
        $.each(chunk, function (index, field) {
            let add = {}
            if (field.name.replace(/\d/g, '') === 'orgName_text') {
                data['orgId'] = field.value;
            }
            if (field.name.replace(/\d/g, '') === 'introFile') {

                add['file'] = field.value
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '1'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'jobFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '0'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'videoFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '2'
                add['type'] = '3'
            }
            if (field.name.replace(/\d/g, '') === 'TeacherFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '0'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'outstandingFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '1'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'TeachersFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '0'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'trainFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '1'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'unitFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '0'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'caseFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '1'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'specialFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '0'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'proofFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '1'
                add['type'] = '2'
            }
            if (field.name.replace(/\d/g, '') === 'sunitFile') {
                add['file'] = field.value;
                add['name'] = field.value.substring(field.value.lastIndexOf('/') + 1);
                add['recommended'] = '0'
                add['type'] = '2'
            }
            if (add.hasOwnProperty('file') && add['file'] !== '') {
                data.declareFileDOS.push(add)
            }
            if (field.name === 'name') {
                data['name'] = field.value;
            }
            if (field.name === 'phone') {
                data['phone'] = field.value;
            }
            if (field.name === 'section') {
                data['section'] = field.value;
            }
            if (field.name === 'job') {
                data['job'] = field.value;
            }
            if (field.name === 'professional') {
                data['professional'] = field.value;
            }
            if (field.name === 'card') {
                data['card'] = field.value;
            }
            if (field.name === 'certType') {
                data['certType'] = field.value;
            }
            switch (typeValue) {
                case typeValue:
                    data['type'] = typeValue
                    break;
                default:
                    break;
            }

            data.declareFileDOS = [...new Set(data.declareFileDOS)]
        });
        list.push(data)
    }
    for (let i = 0; i < list.length; i++) {

        if (typeof list[i].name !='undefined' && list[i].name !== '' && list[i].phone !== '' && list[i].section !== '' ) {
            return list
        } else {
            return []
        }
    }

}


function declareCreate(data) {
    if (null == declareByCreaterId || '' == declareByCreaterId.trim()) {
        $.ajax({
            type: 'POST',
            url: '/jzweb/declare/insertDeclare',
            contentType: 'application/json', // 将content-type设置为application/json
            data: JSON.stringify(data),
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", window.localStorage.getItem("token"))
            },
            dataType: 'json',
            success: function (data) {
                if (data.code === '0') {
                    flag = true
                    layer.msg('申报成功');
                    setTimeout(function () {
                        location.href = '/certificate/declarationFrom'
                    }, 3000)
                    return
                }
                layer.msg(data.msg);
            },
            error: function (xhr, textStatus, error) {
                layer.msg('请求失败');
            }
        });
    } else {
        data.id = declareByCreaterId
        $.ajax({
            type: 'POST',
            url: '/jzweb/declare/updateDeclare',
            contentType: 'application/json', // 将content-type设置为application/json
            data: JSON.stringify(data),
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", window.localStorage.getItem("token"))
            },
            dataType: 'json',
            success: function (data) {
                if (data.code === '0') {
                    flag = true
                    layer.msg('重新申报成功');
                    setTimeout(function () {
                        location.href = '/certificate/declarationFrom'
                    }, 3000)
                    return
                }
                layer.msg(data.msg);
            },
            error: function (xhr, textStatus, error) {
                layer.msg('请求失败');
            }
        });
    }


}

function verifyCreate() {
    let data = $('#signupForm').serializeArray()[0]?$('#signupForm').serializeArray()[0].value:myOrgName
    return new Promise(function (resolve, reject) {
        $.ajax({
            type: 'get',
            url: `/jzweb/declare/verify?orgName=${data}`,
            success: function (data) {
                if (data.code === '0') {
                    certificateNum = data.data
                    resolve(data)
                    return
                }
                resolve(data)


            },
            error: function (xhr, textStatus, error) {
                layer.msg('请求失败');
                reject(error)
            }
        });
    })
}